package com.dushiguang.findhoney.BmobDB;

import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.dushiguang.findhoney.Bean.HoneyInfo;
import com.dushiguang.findhoney.MainActivity_;

import java.util.List;

import cn.bmob.v3.listener.FindListener;

/**
 * Created by ex-dushiguang201 on 2015-11-03.
 */
public class BmobFindListener extends FindListener<HoneyInfo>  {
    private String loginPwd;
    private Context context;

    public BmobFindListener(String loginPwd, Context context) {
        this.loginPwd = loginPwd;
        this.context = context;
    }

    @Override
    public void onSuccess(List<HoneyInfo> list) {
        String pwd = list.get(0).getHoneyLoginPwd();
        list.get(0).getObjectId();
        if (!loginPwd.isEmpty() && loginPwd.equals(pwd)) {
            Toast.makeText(context, "登录成功 ========" + list.get(0).getHoneyLoginPwd() + list.get(0).getObjectId(), Toast.LENGTH_SHORT).show();
            //TODO 将ObjectId存到SharedPreferences,供后续操作Bmob数据使用
            Intent intent = new Intent(context, MainActivity_.class);
            intent.putExtra("ObjectId",list.get(0).getObjectId());
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }
    }

    @Override
    public void onError(int i, String s) {

    }
}
